package Space {
	import flash.filters.GlowFilter;
	import flash.filters.BlurFilter;
	import org.papervision3d.core.geom.Particles;
	import org.papervision3d.core.geom.renderables.Particle;
	import org.papervision3d.materials.special.ParticleMaterial;
	 
	public class SkyMap extends Particles
	{
		
		private var skyRadius:Number;
		private var quantity:int;		
		private var color:int;
		
		public function SkyMap( quantity:int = 1000, particleSize:Number=5, skyRadius:Number = 5000)
		{
			super("ParticleField");
			
			this.material = new ParticleMaterial(0xffffff,1,ParticleMaterial.SHAPE_CIRCLE);
			this.quantity = quantity;
			var Glow:GlowFilter = new GlowFilter(0xFFFF99, 1, 10, 10, 1, 1);
			var Blur:BlurFilter = new BlurFilter(2,2,3);
			this.skyRadius = skyRadius;
			useOwnContainer = true;
			filters = [Glow,Blur]
			createParticles(particleSize);
		}
		
		private function createParticles(size:Number):void
		{
			var c:int;
			var r:int;
			var x:Number;
			var y:Number;
			
			for( var i:Number = 0; i < this.quantity; i++ )
			{
				x = (Math.random() * 300);
				y = (Math.random() * 300);
				
				var myX:Number=skyRadius*(Math.cos(2*Math.PI*x)*Math.sin((90-y)*Math.PI/180));
				var myZ:Number=-skyRadius*(Math.sin(2*Math.PI*x)*Math.sin((90-y)*Math.PI/180));
				var myY:Number=skyRadius*Math.cos((90-y)*Math.PI/180)

				var mySize:Number=size*(5-(Math.random() * 4));
				
				addParticle(new Particle(material as ParticleMaterial, mySize, myX, myY, myZ));
				
			}
		}
		
	}
}